﻿using System;
using HT.Framework;
using UnityEngine;

namespace TG
{
    public class EntityBase : HTBehaviour
    {
        public virtual MapItemType mapItemType { get; }

        public virtual int score { get; }

        public MapCell mapCell;

        private bool isTrigger;

        private void OnTriggerEnter(Collider other)
        {
            if (isTrigger) return;
            Trigger(other.GetComponent<EntityBase>());
        }


        protected virtual void Trigger(EntityBase entity)
        {
            isTrigger = true;
        }

        public virtual void Init(MapCell mapCell)
        {
            this.mapCell = mapCell;
            transform.position = mapCell.position;
        }

        private void OnDisable()
        {
            isTrigger = false;
        }

        public virtual void RemoveSelf()
        {
            //删除自己
            GameManager.Instance.ItemJoinPool(mapCell.mapItemId, mapItemType, this);
        }
    }
}
